package com.cm.caseManagement.controller;


import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmSysOperationLog;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmSysOperationLogService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/log")
public class CmSysOperationLogController extends BaseController
{
    @Autowired
    private ICmSysOperationLogService cmSysOperationLogService;

    /**
     * 查询操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmSysOperationLog cmSysOperationLog)
    {
        startPage();
        List<CmSysOperationLog> list = cmSysOperationLogService.selectCmSysOperationLogList(cmSysOperationLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:export')")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmSysOperationLog cmSysOperationLog)
    {
        List<CmSysOperationLog> list = cmSysOperationLogService.selectCmSysOperationLogList(cmSysOperationLog);
        ExcelUtil<CmSysOperationLog> util = new ExcelUtil<CmSysOperationLog>(CmSysOperationLog.class);
        util.exportExcel(response, list, "操作日志数据");
    }

    /**
     * 获取操作日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmSysOperationLogService.selectCmSysOperationLogById(id));
    }

    /**
     * 新增操作日志
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:add')")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmSysOperationLog cmSysOperationLog)
    {
        return toAjax(cmSysOperationLogService.insertCmSysOperationLog(cmSysOperationLog));
    }

    /**
     * 修改操作日志
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:edit')")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmSysOperationLog cmSysOperationLog)
    {
        return toAjax(cmSysOperationLogService.updateCmSysOperationLog(cmSysOperationLog));
    }

    /**
     * 删除操作日志
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:log:remove')")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmSysOperationLogService.deleteCmSysOperationLogByIds(ids));
    }
}
